package tpf.designer.pattern.course10.producer_consumer.sample5;

import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;

public class Client {
    public static void main(String[] args){
        //因为LinkedBlockingQueue是无界队列，所以生产者会不断去生产，将生产出的任务放在队列中，消费者去队列中去消费
        BlockingQueue blockingQueue = new LinkedBlockingQueue(5);

        //如果改用有界阻塞队列ArrayBlockingQueue，就可以初始化队列的大小。则队列中元素超过队列大小的时候，生产者就会等待消费者消费一个再去生产一个
//        BlockingQueue blockingQueue = new ArrayBlockingQueue(10);

        Producer p = new Producer(blockingQueue);
        Consumer c = new Consumer(blockingQueue);

        Thread tp = new Thread(p);
        Thread tc= new Thread(c);

        tp.start();
        tc.start();
    }
}
